package com.sogoodsoft.entity.app;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.sogoodsoft.entity.IdEntity;

@Entity
@Table(name = "ORGANIZATION")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Organization extends IdEntity {
	
	public java.lang.String name;
	
	public java.lang.String code;
	
	public java.lang.String authority;
	
	public java.lang.String status;

	public java.lang.Long parentId;
	

	public List<Organization> children;
	

	public Organization parent;
	
	public Long odr;
	
	public String type;
	
	public String note;
	
	public String nickName;
	
	/*功能描述和说明*/
	public String description;
	
	@Column(name="node_name")
	public java.lang.String getName() {
		return name;
	}

	public void setName(java.lang.String nodeName) {
		this.name = nodeName;
	}

	public java.lang.String getCode() {
		return code;
	}

	public void setCode(java.lang.String code) {
		this.code = code;
	}

	public java.lang.String getAuthority() {
		return authority;
	}

	public void setAuthority(java.lang.String authority) {
		this.authority = authority;
	}

	public java.lang.String getStatus() {
		return status;
	}

	public void setStatus(java.lang.String status) {
		this.status = status;
	}
	
	@Column(name="parent_id",insertable=false,updatable=false)
	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Long getOdr() {
		return odr;
	}

	public void setOdr(Long odr) {
		this.odr = odr;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Column(name="NICK_NAME")
	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	
	@OneToMany(mappedBy="parent",cascade=CascadeType.ALL)
	@OrderBy("odr asc")
	public List<Organization> getChildren() {
		return children;
	}

	public void setChildren(List<Organization> children) {
		this.children = children;
	}
	

	public boolean hasChildren(){
		if(children.size()>0){
			return true;
		}
		else{
			return false;
		}
	}
	


	@ManyToOne
	@JoinColumn(name="parent_id")
	public Organization getParent() {
		return parent;
	}

	public void setParent(Organization parent) {
		this.parent = parent;
	}
	
	public boolean hasParent(){
		if(parent!=null){
			return true;
		}else{
			return false;
		}
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	
}